package com.yxhl.zoume.core.specialcar.fragment;


import android.content.pm.PackageManager;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.widget.SwipeRefreshLayout;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.core.PoiItem;
import com.jakewharton.rxbinding.view.RxView;
import com.yxhl.zoume.R;
import com.yxhl.zoume.SpecialCarHomeFragmentData;
import com.yxhl.zoume.UIConstants;
import com.yxhl.zoume.ZouMeApplication;
import com.yxhl.zoume.common.ui.fragment.BaseDataBindingFragment;
import com.yxhl.zoume.core.specialcar.model.BizType;
import com.yxhl.zoume.core.specialcar.model.SpecialCarPriceInfo;
import com.yxhl.zoume.core.specialcar.model.SpecialCarSelectedType;
import com.yxhl.zoume.core.specialcar.presenter.SpecialCarHomePresenter;
import com.yxhl.zoume.core.specialcar.activity.SpecialCarContainerActivity;
import com.yxhl.zoume.core.specialcar.model.SpecialCarOrderDispatchFailureEvent;
import com.yxhl.zoume.core.specialcar.view.SpecialCarHomeView;
import com.yxhl.zoume.core.func.map.ui.event.SelectedPOIEvent;
import com.yxhl.zoume.core.func.webpage.info.WebPageEntrance;
import com.yxhl.zoume.core.main.info.HeaderOperationType;
import com.yxhl.zoume.data.http.model.account.ZMAccount;
import com.yxhl.zoume.data.http.rest.param.specialcar.SpecialCarOrderParam;
import com.yxhl.zoume.data.rxbus.RxBus;
import com.yxhl.zoume.di.component.car.DaggerSpecialCarComponent;
import com.yxhl.zoume.di.component.car.SpecialCarComponent;
import com.yxhl.zoume.di.module.ActivityModule;
import com.yxhl.zoume.di.module.car.SpecialCarModule;
import com.yxhl.zoume.navigator.Navigator;
import com.yxhl.zoume.utils.AccountUtils;
import com.yxhl.zoume.utils.LOG;
import com.yxhl.zoume.utils.NetworkUtils;
import com.yxhl.zoume.utils.PromptUtils;
import com.yxhl.zoume.utils.ZMDialog;
import com.yxhl.zoume.utils.permission.PermissionHelper;
import com.yxhl.zoume.utils.timepicker.TimePickerHelper;

import java.util.concurrent.TimeUnit;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;
import rx.Subscription;
import rx.functions.Action1;
import rx.subscriptions.CompositeSubscription;

/**
 * created by sugarya
 */
public class SpecialCarHomeFragment extends BaseDataBindingFragment implements SpecialCarHomeView {

    private static final String TAG = "SpecialCarHomeFrag";

    // 最小数目
    private static final int PASSENGER_NUMBER_MIN = 1;
    private static final int FROM_DEPARTURE_STATION = 1;
    private static final int FROM_ARRIVAL_STATION = 2;
    private static final int MAX_SEAT_COUNT = 4;
    @BindView(R.id.swipe_special_car_root)
    SwipeRefreshLayout mRootSwipeRefresh;
    @BindView(R.id.ll_special_car_container)
    LinearLayout mLinearContainer;
    @BindView(R.id.rl_special_depart_station)
    RelativeLayout mDepartStationRl;
    @BindView(R.id.tv_special_depart_station)
    TextView mDepartStationTv;
    @BindView(R.id.rl_special_arrival_station)
    RelativeLayout mArrivalStationRl;
    @BindView(R.id.tv_special_arrival_station)
    TextView mArrivalStationTv;
    @BindView(R.id.tv_include_reservation_time)
    TextView mTripTimeTv;
    @BindView(R.id.tv_special_out_count)
    TextView mPassengerCountTv;
    @BindView(R.id.frame_fragment_special_car_home_increase)
    FrameLayout mIncreasePassengerFrame;
    @BindView(R.id.iv_special_increase)
    ImageView mIncreasePassengerIv;
    @BindView(R.id.frame_fragment_special_car_home_reduce)
    FrameLayout mReducePassengerFrame;
    @BindView(R.id.iv_special_reduce)
    ImageView mReducePassengerIv;
    @BindView(R.id.ll_special_fee_describe)
    LinearLayout mFeeDescribeLl;
    @BindView(R.id.tv_special_car_line_describe)
    TextView mLineDescribeTv;
    @BindView(R.id.tv_special_reserve_fast_car)
    TextView mReserveFastCarTv;
    @Inject
    SpecialCarHomePresenter mSpecialCarHomePresenter;

    //arguments
    private SpecialCarSelectedType specialCarSelectedType;
    /**
     * 乘客数量
     */
    private int mCount = 1;
    private int mPassengerDefaultMaxCount = 4;
    /**
     * 出发点区域编码
     */
    private String mDepartCode;
    /**
     * 到达地区域编码
     */
    private String mArrivalCode;
    private CompositeSubscription mCompositeSubscription;
    /**
     * 快车下单网络请求类
     */
    private SpecialCarOrderParam mSpecialCarOrderParam;
    /**
     * 选择出发车站/到达车站标志位
     */
    private int mFromStationFlag;
    private Action1<SelectedPOIEvent> mDepartAction;
    private Action1<SelectedPOIEvent> mArrivalAction;
    private Action1<SpecialCarOrderDispatchFailureEvent> mDispatchFailureEventAction;
    private int mScheduleClickCount;

    /**
     * 检查到快车未完成的订单编号
     */
    private String mSpecialCarOrderId;
    private SpecialCarComponent component;
    private SpecialCarHomeFragmentData homeFragmentData;
    private MaterialDialog loadingDialog;


    public SpecialCarHomeFragment() {
        // Required empty public constructor
    }

    public static SpecialCarHomeFragment newInstance() {
        SpecialCarHomeFragment fragment = new SpecialCarHomeFragment();
        return fragment;
    }

    /**
     * RxBus 观察者 回调方法
     *
     * @param
     */
    public void onRxBusEvent() {
        mCompositeSubscription = new CompositeSubscription();
        //准备快车下单请求数据
        mDepartAction = new Action1<SelectedPOIEvent>() {
            @Override
            public void call(SelectedPOIEvent selectedPOIEvent) {
                if (selectedPOIEvent != null) {

                    //显示
                    ((SpecialCarContainerActivity) mActivity).showOneFragmentOnBackPressed(SpecialCarHomeFragment.class.getSimpleName());

                    PoiItem poiItem = selectedPOIEvent.getPoiItem();
                    if (poiItem != null) {
                        //准备快车下单请求数据
                        mSpecialCarOrderParam.setStart(poiItem.getTitle());
                        mDepartCode = poiItem.getAdCode();
                        mSpecialCarOrderParam.setStartCode(mDepartCode);

                        LatLonPoint latLonPoint = poiItem.getLatLonPoint();
                        if (latLonPoint != null) {
                            mSpecialCarOrderParam.setLat(String.valueOf(latLonPoint.getLatitude()));
                            mSpecialCarOrderParam.setLng(String.valueOf(latLonPoint.getLongitude()));
                        }
                        //数据展示
                        mDepartStationTv.setText(poiItem.getTitle());
                        //数据完整性校验
                        checkEnableStatus();
                        //查询价格
                        goToQueryTripPrice();
                    }
                }
            }
        };

        //准备快车下单请求数据
        mArrivalAction = new Action1<SelectedPOIEvent>() {
            @Override
            public void call(SelectedPOIEvent selectedPOIEvent) {
                if (selectedPOIEvent != null) {

                    ((SpecialCarContainerActivity) mActivity).showOneFragmentOnBackPressed(SpecialCarHomeFragment.class.getSimpleName());

                    PoiItem poiItem = selectedPOIEvent.getPoiItem();
                    if (poiItem != null) {
                        //准备快车下单请求数据
                        mSpecialCarOrderParam.setEnd(poiItem.getTitle());
                        mArrivalCode = poiItem.getAdCode();
                        mSpecialCarOrderParam.setEndCityCode(mArrivalCode);

                        LatLonPoint latLonPoint = poiItem.getLatLonPoint();
                        if (latLonPoint != null) {
                            mSpecialCarOrderParam.setElat(String.valueOf(latLonPoint.getLatitude()));
                            mSpecialCarOrderParam.setElng(String.valueOf(latLonPoint.getLongitude()));
                        }

                        mArrivalStationTv.setText(poiItem.getTitle());

                        checkEnableStatus();
                        goToQueryTripPrice();
                    }
                }
            }
        };
        //快车订单失效后,发起包车下单
        mDispatchFailureEventAction = new Action1<SpecialCarOrderDispatchFailureEvent>() {
            @Override
            public void call(SpecialCarOrderDispatchFailureEvent specialCarOrderDispatchFailureEvent) {
                //下单包车
                int orderBizCharter = BizType.ORDER_BIZ_CHARTER;
                int orderType = getOrderType();
                takeSpecialCarOrder(orderBizCharter);
            }
        };

        getSubscription().add(toSubscription(
                SpecialCarOrderDispatchFailureEvent.class,
                mDispatchFailureEventAction,
                new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        LOG.e(TAG, "throwable=" + throwable.toString());
                        onRxBusEvent();
                    }
                }
        ));

    }

    private int getOrderType() {

        int bizType;
        if (specialCarSelectedType == null) {
            bizType = 0;
        } else if (specialCarSelectedType == SpecialCarSelectedType.SELECTED_TYPE_SHARE) {
            bizType = BizType.ORDER_BIZ_SHARE;
        } else {
            bizType = BizType.ORDER_BIZ_CHARTER;
        }

        return bizType;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        mSpecialCarHomePresenter.attachView(this);
        onRxBusEvent();
        initializeSpecialCarOrderParam();
        return view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mRootSwipeRefresh.setEnabled(false);
        checkLastUnFinishSpecialCarOrder();
    }


    private void checkLastUnFinishSpecialCarOrder() {
        mSpecialCarHomePresenter.queryLastUnFinishOrder();
    }

    private void initializeSpecialCarOrderParam() {
        mSpecialCarOrderParam = new SpecialCarOrderParam();
    }

    /**
     * 出发车站 点击监听
     */
    @OnClick(R.id.tv_special_depart_station)
    void onDepartStationClick() {

        mCompositeSubscription.clear();
        mFromStationFlag = FROM_DEPARTURE_STATION;

        Subscription departSubscription = RxBus.getInstance().toSubscription(
                SelectedPOIEvent.class,
                mDepartAction,
                new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        Log.e(TAG, "throwable=" + throwable.toString());
                        onRxBusEvent();
                    }
                }
        );
        mCompositeSubscription.add(departSubscription);

        goToDepartStationMap();

    }

    /**
     * 到达车站 点击监听
     */
    @OnClick(R.id.tv_special_arrival_station)
    void onArrivalStationClick() {
        mCompositeSubscription.clear();
        mFromStationFlag = FROM_ARRIVAL_STATION;

        Subscription arrivalSubscription = RxBus.getInstance().toSubscription(
                SelectedPOIEvent.class,
                mArrivalAction,
                new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        Log.e(TAG, "throwable=" + throwable.toString());
                        onRxBusEvent();
                    }
                }
        );
        mCompositeSubscription.add(arrivalSubscription);

        goToArrivalStationMap();
    }

    /**
     * 跳转到出发地点
     */
    private void goToDepartStationMap() {
        boolean checkLocationPermission = PermissionHelper.checkLocationPermission(mActivity);
        if (checkLocationPermission) {
            ((SpecialCarContainerActivity) mActivity).navigateDepartStationMap();
        } else {
            PermissionHelper.takeLocationPermission(this, PermissionHelper.REQUEST_CODE_STATION_MAP_DEPART_LOCATION);
        }
    }

    /**
     * 跳转到目的地点
     */
    private void goToArrivalStationMap() {
        boolean checkLocationPermission = PermissionHelper.checkLocationPermission(mActivity);
        if (checkLocationPermission) {
            ((SpecialCarContainerActivity) mActivity).navigateArrivalStationMap();
        } else {
            PermissionHelper.takeLocationPermission(this, PermissionHelper.REQUEST_CODE_STATION_MAP_ARRIVAL_LOCATION);
        }
    }

    /**
     * 出行时间 点击监听
     *
     * @param view
     */
    @OnClick(R.id.tv_include_reservation_time)
    public void onTripTimeClick(View view) {
        if (view != null) {
            int viewId = view.getId();
            switch (viewId) {
                case R.id.tv_include_reservation_time:
                    showOutTimePopup();
                    break;
            }
        }
    }

    /**
     * 出行时间 弹窗
     */
    private void showOutTimePopup() {
        TimePickerHelper.newInstance(mActivity).showSpecialCarPicker(new TimePickerHelper.SpecialCarPickerSelectListener() {
            @Override
            public void onConfirmPick(String optionResult1, String optionResult2) {
                LOG.e(TAG, "optionResult1=" + optionResult1 + " optionResult2=" + optionResult2);
                if (!TextUtils.isEmpty(optionResult1)) {
                    if (mTripTimeTv != null) {
                        mTripTimeTv.setText(optionResult1);
                        checkEnableStatus();
                    }
                }
                mSpecialCarOrderParam.setDepartTime(optionResult2);
            }
        });
    }

    /**
     * 增加乘客数量,乘客数量 点击监听
     *
     * @param view
     */
    @OnClick({R.id.frame_fragment_special_car_home_reduce, R.id.frame_fragment_special_car_home_increase})
    public void onTravellerCountClick(View view) {
        if (view != null) {
            int viewId = view.getId();
            switch (viewId) {
                case R.id.frame_fragment_special_car_home_reduce:
                    if (mCount > PASSENGER_NUMBER_MIN) {
                        mCount--;
                    }

                    break;
                case R.id.frame_fragment_special_car_home_increase:
                    if (mCount < mPassengerDefaultMaxCount) {
                        mCount++;
                    }

                    break;
            }
            mPassengerCountTv.setText(String.valueOf(mCount));

            if (mCount <= 1) {
                mReducePassengerIv.setImageResource(R.drawable.ic_reduce_gray);
                mReducePassengerFrame.setClickable(false);
            } else if (mCount < mPassengerDefaultMaxCount) {
                mReducePassengerIv.setImageResource(R.drawable.ic_reduce);
                mIncreasePassengerIv.setImageResource(R.drawable.ic_increase);
                mReducePassengerFrame.setClickable(true);
                mIncreasePassengerFrame.setClickable(true);
            } else {
                mIncreasePassengerIv.setImageResource(R.drawable.ic_increase_gray);
                mIncreasePassengerFrame.setClickable(false);
            }
        }
    }


    /**
     * 拼车、包车选择按钮
     *
     * @param view
     */
    @OnClick({R.id.rl_unit_price, R.id.rl_chartered_bus})
    public void onSpecialCarOrderTypeClick(View view) {
        if (view != null) {
            switch (view.getId()) {
                case R.id.rl_unit_price: {//拼车点击
                    shareClicked();
                    break;
                }
                case R.id.rl_chartered_bus: {//包车点击
                    charterClicked();
                    break;
                }
            }
            checkEnableStatus();
        }
    }

    /**
     * 包车点击
     */
    private void charterClicked() {
        if (specialCarSelectedType == null || specialCarSelectedType == SpecialCarSelectedType.SELECTED_TYPE_SHARE) {
            charterSelected();
        } else {
            showPricingRules();
        }
    }

    /**
     * 包车选中状态
     */
    private void charterSelected() {
        specialCarSelectedType = SpecialCarSelectedType.SELECTED_TYPE_CHARTER;
        homeFragmentData.setSelectedType(specialCarSelectedType);
    }

    /**
     * 拼车点击
     */
    private void shareClicked() {
        if (specialCarSelectedType == null || specialCarSelectedType == SpecialCarSelectedType.SELECTED_TYPE_CHARTER) {
            shareSelected();
        } else {
            showPricingRules();
        }
    }

    /**
     * 显示计价规则
     */
    private void showPricingRules() {
        getAppComponent().navigator().navigateToWebPageActivity(mActivity, WebPageEntrance.SPECIAL_CAR_PRICE_INTRODUCTION);
    }

    /**
     * 拼车选中状态
     */
    private void shareSelected() {
        specialCarSelectedType = SpecialCarSelectedType.SELECTED_TYPE_SHARE;
        homeFragmentData.setSelectedType(specialCarSelectedType);
    }

    /**
     * 下单点击监听
     *
     * @param view
     */
    @OnClick({R.id.tv_special_reserve_fast_car})
    public void onSpecialCarScheduleClick(final View view) {
        if (view != null) {
            final int viewId = view.getId();
            mScheduleClickCount++;

            RxView.clicks(view).throttleFirst(1000, TimeUnit.MICROSECONDS).subscribe(new Action1<Void>() {
                @Override
                public void call(Void aVoid) {
                    mScheduleClickCount = 0;
                    takeSpecialCarOrder(getOrderType());
                }
            });

            if (mScheduleClickCount == 1) {
                mReserveFastCarTv.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        if (mScheduleClickCount == 1) {
                            mScheduleClickCount = 0;
                            takeSpecialCarOrder(getOrderType());
                        }
                    }
                }, 200);
            }
        }
    }

    /**
     * 点击预约包车 和 拼车 跳转到
     *
     * @param orderType 快车订单类型
     */
    private void takeSpecialCarOrder(int orderType) {
        SpecialCarOrderParam reserveOrderParam = getSpecialCarOrderParam(orderType);
        if (reserveOrderParam.checkData()) {
            loadingDialog = ZMDialog.getLoadingDialog(mActivity);
            loadingDialog.show();
            mSpecialCarHomePresenter.getSpecialCarOrder(reserveOrderParam);
        } else {
            PromptUtils.showShort(getContext(), getString(R.string.special_car_select_hint));
        }
    }

    /**
     * 快车下单 网络请求字段设置
     *
     * @param bizType
     * @return
     */
    private SpecialCarOrderParam getSpecialCarOrderParam(int bizType) {
        ZMAccount account = AccountUtils.getInstance(getContext()).getAccount();
        if (account != null) {
            String mobile = account.getAccountName();
            String token = account.getAccessToken();
            mSpecialCarOrderParam.setMobile(mobile).setToken(token);
        }
        if (mCount == 0) {
            String passengerCount = mPassengerCountTv.getText().toString().trim();
            try {
                mCount = Integer.parseInt(passengerCount);
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
        }
        mSpecialCarOrderParam.setAmount(mCount);
        mSpecialCarOrderParam.setBizType(bizType);
        mSpecialCarOrderParam.setClientSystem(UIConstants.CLIENT_SYSTEM);
        mSpecialCarOrderParam.setNeedFerry(false);

        return mSpecialCarOrderParam;
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        LOG.e(TAG, "onHiddenChanged hidden=" + hidden);
        if (!hidden) {
            setupToolBar();
        }
    }


    /**
     * 判断出发地点,到达地点,出行时间数据有效性
     *
     * @return
     */
    private boolean validateDepartAndArrivalAndTripTimeData() {

        String startLocationStr = mDepartStationTv.getText().toString().trim();
        String arrivalLocationStr = mArrivalStationTv.getText().toString().trim();
        String tripTimeStr = mTripTimeTv.getText().toString().trim();

        if (TextUtils.isEmpty(startLocationStr)) {
            return false;
        }

        if (TextUtils.isEmpty(arrivalLocationStr)) {
            return false;
        }

        if (TextUtils.isEmpty(tripTimeStr)) {
            return false;
        }

        if (specialCarSelectedType == null) {
            return false;
        }

        return true;
    }

    /**
     * 核对快车下单按钮状态
     */
    private void checkEnableStatus() {
        if (validateDepartAndArrivalAndTripTimeData()) {
            mReserveFastCarTv.setEnabled(true);
        } else {
            mReserveFastCarTv.setEnabled(false);
        }
    }

    @Override
    public void renderUnFinishOrderOnSuccess(String orderId) {
        if (!TextUtils.isEmpty(orderId)) {
            navigateToScheduleActivity(orderId);
        }
    }

    @Override
    public void renderUnFinishOrderOnCompleted() {
    }

    /**
     * 包车出行/拼车出行跳转到地图页面
     * Ethan
     *
     * @param orderId 快车未完成的订单编号
     */
    public void navigateToScheduleActivity(String orderId) {
        boolean checkLocationPermission = PermissionHelper.checkLocationPermission(mActivity);
        if (checkLocationPermission) {
            ZouMeApplication.application.getAppComponent().navigator().navigateToSpecialCarScheduleActivity(mActivity, orderId);
        } else {
            mSpecialCarOrderId = orderId;
            PermissionHelper.takeLocationPermission(this, PermissionHelper.REQUEST_CODE_SCHEDULE_MAP_LOCATION);
        }
        mActivity.finish();
    }

    /**
     * 请求网络获取行程费用
     */
    private void goToQueryTripPrice() {
        if (!isEmptyEitherDepartOrArrivalStation()) {
            if (NetworkUtils.getInstance(mActivity).isConnected()) {
                mSpecialCarHomePresenter.queryTripPrice(mDepartCode, mArrivalCode);
            } else {
                PromptUtils.showShort(mActivity, getString(R.string.network_not_available));
                //网络没信号,乘客人数设置成初始化状态
                if (mCount > MAX_SEAT_COUNT) {
                    mPassengerDefaultMaxCount = MAX_SEAT_COUNT;
                    mCount = MAX_SEAT_COUNT;
                    mPassengerCountTv.setText(String.valueOf(MAX_SEAT_COUNT));
                }
            }
        }
    }

    /**
     * 出发站点 到达站点 网络请求前的非空判断
     *
     * @return
     */
    private boolean isEmptyEitherDepartOrArrivalStation() {
        String departStationStr = mDepartStationTv.getText().toString().trim();
        String arrivalStationStr = mArrivalStationTv.getText().toString().trim();

        return TextUtils.isEmpty(departStationStr) || TextUtils.isEmpty(arrivalStationStr);
    }


    @Override
    public void renderPriceQueryOnSuccess(SpecialCarPriceInfo specialCarPriceInfo) {
        //线路座位
        int lastedMaxSeat = specialCarPriceInfo.getMaxSeat();
        if (lastedMaxSeat < mCount) {
            mCount = lastedMaxSeat;
            mPassengerCountTv.setText(String.valueOf(lastedMaxSeat));
        }
        mPassengerDefaultMaxCount = lastedMaxSeat;
        homeFragmentData.setSpecialCarPriceInfoDetail(specialCarPriceInfo);
    }

    @Override
    public void renderSpecialCarOrderOnSuccess(String orderId) {
        navigateToScheduleActivity(orderId);

    }

    @Override
    public void renderSpecialCarOrderOnFailure(String resultMessage) {
        if (!TextUtils.isEmpty(resultMessage)) {
            switch (mFromStationFlag) {
                case FROM_DEPARTURE_STATION:
                    PromptUtils.showShortSnackBar(mDepartStationRl, resultMessage);
                    break;
                case FROM_ARRIVAL_STATION:
                    PromptUtils.showShortSnackBar(mArrivalStationRl, resultMessage);
                    break;
            }
        }
    }

    @Override
    public void renderSpecialCarOrderOnError() {
        PromptUtils.showShort(mActivity, getString(R.string.special_car_query_error));
    }

    @Override
    public void renderSpecialCarOrderOnCompleted() {
        loadingDialog.dismiss();
    }


    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (grantResults != null && grantResults.length >= 1) {
            Navigator navigator = ZouMeApplication.application.getAppComponent().navigator();
            switch (requestCode) {
                //快车行程地图
                case PermissionHelper.REQUEST_CODE_SCHEDULE_MAP_LOCATION:
                    //判断用户是或同意了授权
                    if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                        navigator.navigateToSpecialCarScheduleActivity(mActivity, mSpecialCarOrderId);
                    } else {
                        PromptUtils.showShort(getContext(), getString(R.string.permission_location_deny_message));
                    }
                    break;
                //快车出发站点
                case PermissionHelper.REQUEST_CODE_STATION_MAP_DEPART_LOCATION:
                    if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                        ((SpecialCarContainerActivity) mActivity).navigateDepartStationMap();
                    } else {
                        PromptUtils.showShort(getActivity(), getString(R.string.permission_location_deny_message));
                    }
                    break;
                //快车到达站点
                case PermissionHelper.REQUEST_CODE_STATION_MAP_ARRIVAL_LOCATION:
                    if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                        ((SpecialCarContainerActivity) mActivity).navigateArrivalStationMap();
                    } else {
                        PromptUtils.showShort(getActivity(), getString(R.string.permission_location_deny_message));
                    }
                    break;
            }
        }
    }

    @Override
    public void onDestroyView() {
        mSpecialCarHomePresenter.onDestroy();
        mCompositeSubscription.unsubscribe();
        mCompositeSubscription = null;
        super.onDestroyView();
    }


    @Override
    protected void initializeInjector() {
        component = DaggerSpecialCarComponent.builder()
                .appComponent(getAppComponent())
                .activityModule(new ActivityModule(getActivity()))
                .specialCarModule(new SpecialCarModule())
                .build();
        component.inject(this);
    }

    @Override
    protected View getContentLayout(LayoutInflater inflater, ViewGroup container) {
        homeFragmentData = DataBindingUtil.inflate(inflater, R.layout.fragment_special_car_home, container, false);
        return homeFragmentData.getRoot();
    }

    @Override
    protected void setupToolBar() {
        if (mActivity instanceof SpecialCarContainerActivity) {
            SpecialCarContainerActivity containerActivity = (SpecialCarContainerActivity) mActivity;
            containerActivity.setToolbar(
                    getString(R.string.special_car_header_title),
                    getString(R.string.passenger_must_know)
            );
            containerActivity.setHeaderRightTag(HeaderOperationType.PASSENGER_NOCIE);
            containerActivity.setToolbarVisible(true);
        }
    }
}
